﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Streambolics.Gui;
using System.Windows.Forms;

namespace Streambolics.Tablet
{
    public class InkAdapterSubMenu : SubMenu
    {
        private InkAdapter _Adapter;
        private ToolStripMenuItem _Recognized;

        public InkAdapter Adapter
        {
            get
            {
                return _Adapter;
            }
            set
            {
                if (_Adapter != value)
                {
                    _Adapter = value;
                    DoBuildMenu ();
                }
            }
        }

        protected override void OnBuildMenu (EventArgs e)
        {
            base.OnBuildMenu (e);
            if (_Adapter != null)
            {
                ToolStripMenuItem clr = new ToolStripMenuItem ("Clear");
                clr.Click += delegate (object sender, EventArgs ee)
                {
                    _Adapter.Clear ();
                };
                Add (clr);
                _Recognized = new ToolStripMenuItem ("Recognized texts");
                Add (_Recognized);
            }
        }

        protected override void OnRedraw (EventArgs e)
        {
            base.OnRedraw (e);
            if (_Recognized != null)
            {
                bool found = false;
                _Recognized.DropDownItems.Clear ();
                foreach (string s in _Adapter.RecognizedTexts)
                {
                    found = true;
                    _Recognized.DropDownItems.Add (s);
                }
                if (!found)
                {
                    _Recognized.DropDownItems.Add ("Nothing...");
                }
            }
        }
    }
}
